rendericon: Move a function
authorBenjamin Otte <otte@redhat.com>
Wed, 16 Dec 2015 01:15:20 +0000 (02:15 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 16 Dec 2015 03:46:22 +0000 (04:46 +0100)
The function is identical if used for builtin icons and regular icons
(as per iconhelper). So split it out in a way that doesn't assume
either.

gtk/gtkrendericon.c
gtk/gtkrendericonprivate.h
gtk/gtkstylecontext.c

index 411050a6b5ca1b7760c52e9a243c8be427a13e58..2c756a4929db8565d5b20d8d4e86388776d4d0fe 100644 (file)
@@ -27,6 +27,8 @@
 #include "gtkcssstyleprivate.h"
 #include "gtkcsstransformvalueprivate.h"
 
+#include <math.h>
+
 void
 gtk_css_style_render_icon (GtkCssStyle            *style,
                            cairo_t                *cr,
@@ -144,3 +146,75 @@ gtk_css_style_render_icon_surface (GtkCssStyle            *style,
   cairo_set_matrix (cr, &saved_matrix);
 }
 
+static void
+gtk_cairo_rectangle_transform (cairo_rectangle_int_t       *dest,
+                               const cairo_rectangle_int_t *src,
+                               const cairo_matrix_t        *matrix)
+{
+  double x1, x2, x3, x4;
+  double y1, y2, y3, y4;
+
+  g_return_if_fail (dest != NULL);
+  g_return_if_fail (src != NULL);
+  g_return_if_fail (matrix != NULL);
+
+  x1 = src->x;
+  y1 = src->y;
+  x2 = src->x + src->width;
+  y2 = src->y;
+  x3 = src->x + src->width;
+  y3 = src->y + src->height;
+  x4 = src->x;
+  y4 = src->y + src->height;
+
+  cairo_matrix_transform_point (matrix, &x1, &y1);
+  cairo_matrix_transform_point (matrix, &x2, &y2);
+  cairo_matrix_transform_point (matrix, &x3, &y3);
+  cairo_matrix_transform_point (matrix, &x4, &y4);
+
+  dest->x = floor (MIN (MIN (x1, x2), MIN (x3, x4)));
+  dest->y = floor (MIN (MIN (y1, y2), MIN (y3, y4)));
+  dest->width = ceil (MAX (MAX (x1, x2), MAX (x3, x4))) - dest->x;
+  dest->height = ceil (MAX (MAX (y1, y2), MAX (y3, y4))) - dest->y;
+}
+
+void
+gtk_css_style_render_icon_get_extents (GtkCssStyle  *style,
+                                       GdkRectangle *extents,
+                                       gint          x,
+                                       gint          y,
+                                       gint          width,
+                                       gint          height)
+{
+  cairo_matrix_t transform_matrix, matrix;
+  GtkBorder border;
+  GdkRectangle rect;
+
+  g_return_if_fail (GTK_IS_CSS_STYLE (style));
+  g_return_if_fail (extents != NULL);
+
+  extents->x = x;
+  extents->y = y;
+  extents->width = width;
+  extents->height = height;
+
+  if (!_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
+    return;
+  
+  cairo_matrix_init_translate (&matrix, x + width / 2.0, y + height / 2.0);
+  cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
+  /* need to round to full pixels */
+  rect.x = - (width + 1) / 2;
+  rect.y = - (height + 1) / 2;
+  rect.width = (width + 1) & ~1;
+  rect.height = (height + 1) & ~1;
+  gtk_cairo_rectangle_transform (extents, &rect, &matrix);
+
+  _gtk_css_shadows_value_get_extents (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW), &border);
+
+  extents->x -= border.left;
+  extents->y -= border.top;
+  extents->width += border.left + border.right;
+  extents->height += border.top + border.bottom;
+}
+
index a92735a96aa96c5cf835af52ac26400a00324548..f627655f2a7caedcf337bda3c98679fa79ddf958 100644 (file)
@@ -42,6 +42,13 @@ void    gtk_css_style_render_icon_surface       (GtkCssStyle            *style,
                                                  double                  x,
                                                  double                  y);
 
+void    gtk_css_style_render_icon_get_extents   (GtkCssStyle            *style,
+                                                 GdkRectangle           *extents,
+                                                 gint                    x,
+                                                 gint                    y,
+                                                 gint                    width,
+                                                 gint                    height);
+
 G_END_DECLS
 
 #endif /* __GTK_RENDER_ICON_PRIVATE_H__ */
index 65ebe68697400e0ed9b1a42f28c30a06c971a66b..7fe5f3cf8a6b7f5b08808dc5fd64f71e36734bea 100644 (file)
 
 #include "config.h"
 
+#include "gtkstylecontextprivate.h"
+
 #include <gdk/gdk.h>
 #include <math.h>
 #include <stdlib.h>
 #include <gobject/gvaluecollector.h>
 
-#include "gtkstylecontextprivate.h"
 #include "gtkcontainerprivate.h"
 #include "gtkcssanimatedstyleprivate.h"
 #include "gtkcsscolorvalueprivate.h"
 #include "gtkcsstransientnodeprivate.h"
 #include "gtkcsswidgetnodeprivate.h"
 #include "gtkdebug.h"
-#include "gtktypebuiltins.h"
 #include "gtkintl.h"
-#include "gtkwindow.h"
 #include "gtkprivate.h"
-#include "gtkwidgetpath.h"
-#include "gtkwidgetprivate.h"
-#include "gtkstylecascadeprivate.h"
-#include "gtkstyleproviderprivate.h"
+#include "gtkrendericonprivate.h"
 #include "gtksettings.h"
 #include "gtksettingsprivate.h"
+#include "gtkstylecascadeprivate.h"
+#include "gtkstyleproviderprivate.h"
+#include "gtktypebuiltins.h"
+#include "gtkwindow.h"
+#include "gtkwidgetpath.h"
+#include "gtkwidgetprivate.h"
 
 #include "deprecated/gtkgradientprivate.h"
 #include "deprecated/gtksymboliccolorprivate.h"
@@ -3033,37 +3035,6 @@ gtk_style_context_get_change (GtkStyleContext *context)
   return context->priv->invalidating_context;
 }
 
-static void
-gtk_cairo_rectangle_transform (cairo_rectangle_int_t       *dest,
-                               const cairo_rectangle_int_t *src,
-                               const cairo_matrix_t        *matrix)
-{
-  double x1, x2, x3, x4;
-  double y1, y2, y3, y4;
-
-  g_return_if_fail (dest != NULL);
-  g_return_if_fail (src != NULL);
-  g_return_if_fail (matrix != NULL);
-
-  x1 = src->x;
-  y1 = src->y;
-  x2 = src->x + src->width;
-  y2 = src->y;
-  x3 = src->x + src->width;
-  y3 = src->y + src->height;
-  x4 = src->x;
-  y4 = src->y + src->height;
-
-  cairo_matrix_transform_point (matrix, &x1, &y1);
-  cairo_matrix_transform_point (matrix, &x2, &y2);
-  cairo_matrix_transform_point (matrix, &x3, &y3);
-  cairo_matrix_transform_point (matrix, &x4, &y4);
-
-  dest->x = floor (MIN (MIN (x1, x2), MIN (x3, x4)));
-  dest->y = floor (MIN (MIN (y1, y2), MIN (y3, y4)));
-  dest->width = ceil (MAX (MAX (x1, x2), MAX (x3, x4))) - dest->x;
-  dest->height = ceil (MAX (MAX (y1, y2), MAX (y3, y4))) - dest->y;
-}
 void
 _gtk_style_context_get_icon_extents (GtkStyleContext *context,
                                      GdkRectangle    *extents,
@@ -3072,10 +3043,6 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
                                      gint             width,
                                      gint             height)
 {
-  cairo_matrix_t transform_matrix, matrix;
-  GtkBorder border;
-  GdkRectangle rect;
-
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
   g_return_if_fail (extents != NULL);
 
@@ -3085,29 +3052,9 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
       return;
     }
 
-  extents->x = x;
-  extents->y = y;
-  extents->width = width;
-  extents->height = height;
-
-  if (!_gtk_css_transform_value_get_matrix (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix))
-    return;
-  
-  cairo_matrix_init_translate (&matrix, x + width / 2.0, y + height / 2.0);
-  cairo_matrix_multiply (&matrix, &transform_matrix, &matrix);
-  /* need to round to full pixels */
-  rect.x = - (width + 1) / 2;
-  rect.y = - (height + 1) / 2;
-  rect.width = (width + 1) & ~1;
-  rect.height = (height + 1) & ~1;
-  gtk_cairo_rectangle_transform (extents, &rect, &matrix);
-
-  _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SHADOW), &border);
-
-  extents->x -= border.left;
-  extents->y -= border.top;
-  extents->width += border.left + border.right;
-  extents->height += border.top + border.bottom;
+  gtk_css_style_render_icon_get_extents (gtk_style_context_lookup_style (context),
+                                         extents,
+                                         x, y, width, height);
 }
 
 static PangoUnderline